package com.zhong.gang.app.ui.zhongzhuan.fa;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.content.Intent;
import android.view.View;
import com.zhong.gang.app.R;
import com.zhong.gang.app.api.Api;
import com.zhong.gang.app.databinding.ActivityZhongZhuanFaBinding;
import com.zhong.gang.app.db.UserBean;
import com.zhong.gang.app.db.UserUtils;
import com.zhong.gang.app.ui.address.AddressAct;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.config.Config;
import com.zhong.gang.applib.controller.ImgController;
import com.zhong.gang.applib.ui.adapter.AddImgAdapter;
import com.zhong.gang.applib.ui.chese.MaterialAct;

public class ZhongZhuanFaAct extends ActBase<ActivityZhongZhuanFaBinding> {
    private ZhongZhuanFaPersenter persenter;
    private AddImgAdapter allImgAdapter,halfImgAdapter;
    private ImgController imgController;

    @Override
    public int LayoutRes() {
        return R.layout.activity_zhong_zhuan_fa;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public void initView() {
        bind.setAct(this);
        persenter = new ZhongZhuanFaPersenter(this,bind);
        imgController = new ImgController();
        allImgAdapter = imgController.initImgAdapter(this,bind.allRecyclerView, Config.ALL_CLICKED);
        halfImgAdapter = imgController.initImgAdapter(this,bind.halfRecyclerView,Config.HALF_CLICKED);
        imgController.addImgView(allImgAdapter,"",true);
        imgController.addImgView(halfImgAdapter,"",true);
        imgController.setNeedImg(allImgAdapter,this,true,Config.ALL_CLICKED,true);
        imgController.setNeedImg(halfImgAdapter,this,true,Config.HALF_CLICKED,true);
    }


    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.gangchang:
                AddressAct.openAct(this,Api.gangChangeList,persenter);
                break;
            case R.id.type_layout:
                if (persenter.getAddressBean() != null) {
                    UserBean userBean = UserUtils.getIntent(this).getUser();
                    MaterialAct.openAct(this, Api.materialTypeList,
                            persenter.getAddressBean().getId() + "", "1",
                            userBean.isLogin(), userBean.getToken(), userBean.getId() + "",
                            UserUtils.getIntent(this).getRoleId() + "", persenter);
                }
                break;
            case R.id.sure://下一步
                persenter.next(imgController.getFile(halfImgAdapter),imgController.getFile(allImgAdapter));
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        imgController.onActivityResult(requestCode == Config.ALL_CLICKED?allImgAdapter:halfImgAdapter,resultCode,data);
        if (resultCode != RESULT_OK || data == null)
            return;
    }
}

